import Vue from 'vue'
// Vue.forceUpdate()
import App from './App'

// store
import store from './store'
Vue.prototype.$store = store;

// mixin
import global from '@/apiPost/mixin.js'
Vue.prototype.global = global;



// 数据接口
import httpApi from '@/apiPost/request.js'
const post = httpApi.post;
const upload = httpApi.upload;

// 上传接口
import uploadApi from '@/apiPost/uploadConfig.js'
const complaintApi = uploadApi.complaintApi

// 定义的方法
// import unit from '@/components/unit.js'
// Vue.prototype.$unit = unit;

Vue.prototype.$api = {
	post,
	// msg
	upload,
	complaintApi
};

import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom', cuCustom)

import goodspoor from './pages/goodspoor/index.vue'
Vue.component('goodspoor', goodspoor)



import socity from './pages/goodspoor/socity.vue'
Vue.component('socity', socity)


import market from './pages/market/index.vue'
Vue.component('market', market)

import tabbar from './pages/index/tabbar.vue'
Vue.component('tabbar', tabbar)

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
	...App
})

import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

// 引入uView对小程序分享的mixin封装
let mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare)


app.$mount()
import globals from 'utils/util.js'
Vue.prototype.$globals = globals;

//欧气一番 小程序tag
Vue.prototype.$mpVer = "v2"

const trylogin = (i) => {
	uni.navigateTo({
		url: `/pages/login/login?name=` + i
	})
	return
	/*uni.reLaunch({
		url: `/pages/login/login`
	});*/
	var _this = this;
	wx.showModal({
		title: '温馨提示',
		content: '正在请求您的个人信息',
		success(res) {
			if (res.confirm) {
				wx.getUserProfile({
					desc: "获取你的昵称、头像、地区及性别",
					success: function(res) {
						uni.showLoading({
							title: '登录中...'
						});
						uni.login({
							provider: 'weixin',
							success: function(loginRes) {
								let code = loginRes.code;
								uni.request({
									url: globals.apibase +
										'/api/Minlogin/login',
									data: {
										code: code,
										avatar: res.userInfo.avatarUrl,
										nickname: res.userInfo.nickName,
										gender: res.userInfo.gender,
										encryptedData: res.encryptedData,
										iv: res.iv,
										ver: "v2"
									},
									method: 'POST',
									header: {
										'content-type': 'application/json'
									},
									success: (res) => {
										if (res.data.code == '1') {
											uni.setStorageSync('token',
												res.data.data.token);
											uni.hideLoading();
										}
									}
								});
							},
						});
					}
				})
			}
		}
	})
}


// 加密
const mdnum = () => {
	let num = ''
	for (var i = 0; i < 5; i++) {
		let d = uni.$u.random(0, 9)
		num = num + d
	}

	const date = (new Date().getTime() / 1000).toFixed(0);
	var str = date + 'akd!k123#dfg' + num
	var arr = new Array(date, str, num);
	return arr;
}

Vue.prototype.$uniApi = {
	trylogin,
	mdnum
};
import webSocketClass from 'utils/websocketStore.js'
Vue.prototype.$websocket = webSocketClass